#include <iostream>
#include "binarytree.h"

using namespace std;

void print(char c)
{
    cout << c;
}

int main()
{
    // 建立二叉树
    //      -
    //  a        *
    //         b   c
    auto pa = new BiTNode<char>{'a', nullptr, nullptr};
    auto pb = new BiTNode<char>{'b', nullptr, nullptr};
    auto pc = new BiTNode<char>{'c', nullptr, nullptr};
    auto pm = new BiTNode<char>{'*', pb, pc};
    auto ps = new BiTNode<char>{'-', pa, pm};

    auto T = ps;

    // 先序遍历 中序遍历 后序遍历

    Preorder(T, print);
    cout << endl;
    Inorder(T, print);
    cout << endl;
    Postorder(T, print);
    cout << endl;

    // 打印二叉树
    Print(T);

    // 节点数 叶子节点数 高度
    cout << "NodeCount: " << NodeCount(T) << endl;
    cout << "LeafCount: " << LeafCount(T) << endl;
    cout << "Depth: " << Depth(T) << endl;

    // 销毁二叉树
    Destroy(T);
    Print(T);

    // 建立二叉树
    BiTree<char> t=nullptr;
    t=CreateBinaryTree();
    Print(t);

    Destroy(t);

    // 建立二叉树
    T=CreateBinaryTree();
    Print(T);

    std::cout << "Destroy" << std::endl;
    Destroy(T);
    Print(T);

    BiTree<int> bst=nullptr;
    int a[]={13,24,37,90,53,40,20};
    for(int x:a) InsertBST(bst,x);
    Print(bst);

    std::cout << "Min" << FindMinBST(bst)->data<< std::endl;
    std::cout << "Max"<<FindMaxBST(bst)->data << std::endl;

    std::cout << "Delete"<<40 << std::endl;
    DeleteBST(bst,40);
    Print(bst);

    std::cout << "Detele"<<37 << std::endl;
    DeleteBST(bst,37);
    Print(bst);

    std::cout << "Detele"<<24<< std::endl;
    DeleteBST(bst,24);
    Print(bst);

    Destroy(bst);
    return 0;
}